<script setup lang='ts' name="user-managemengt-detail">
import { getNewCompanyOrgDetail } from '@fl/api/iam-api'
import { useAesDecrypt } from '@fl/hooks/web/useCrypt'
import { ElButton, ElCard, ElCol, ElForm, ElFormItem, ElRow } from 'element-plus'
import { cloneDeep } from 'lodash-es'
import { toRefs, watch } from 'vue'
import { useRouter } from 'vue-router'

import { useDicts } from '../../../company-org/hooks/use-dicts'

const props = withDefaults(defineProps<{
    modelValue: boolean
    showId?: string
}>(), {

})

const emits = defineEmits(['update:modelValue', 'confirm'])
const router = useRouter()

const { useDict } = useDicts()

const { showId } = toRefs(props)
const initialDetail = {
    businessLicense: '',
    catName: '',
    catType: '',
    cooperationType: '',
    email: '',
    enterpriseAccount: '',
    enterpriseId: '',
    enterpriseLevel: '',
    enterpriseLevelId: '',
    enterpriseName: '',
    enterpriseObjectID: '',
    enterpriseShort: '',
    establishmenDate: '',
    id: '',
    idCard: '',
    legalCard: '',
    legalCardBack: '',
    legalCardFront: '',
    legalRepresentative: '',
    parentId: '',
    phonenumber: '',
    registeredAddress: '',
    status: '',
    unifiedSocialCreditCode: '',
    userName: '',
}
const detail = ref(cloneDeep(initialDetail))

function onSubmit() {
    router.push(`/house-source-center/fair/user-management-edit?id=${detail.value.id}`)
}

function goToList() {
    emits('update:modelValue', true)
}

function getDetail() {
    getNewCompanyOrgDetail(showId.value).then((res: any) => {
        if (res.code === 200) {
            detail.value = res.data
            console.log('detail', detail.value)
        }
    })
}

watch(showId, (val: any) => {
    if (val) {
        getDetail()
    }
}, {
    deep: true,
    immediate: true,
})
</script>

<template>
    <ElCard class="mb-20">
        <ElRow>
            <ElButton @click="goToList">
                返回列表
            </ElButton>
        </ElRow>

        <div class="info-title">
            企业注册信息
        </div>

        <ElForm :model="detail"
                label-width="auto"
        >
            <ElRow :gutter="20">
                <ElCol :span="8">
                    <ElFormItem label="企业号:">
                        {{ detail.enterpriseId }}
                    </ElFormItem>
                </ElCol>
            </ElRow>

            <ElRow :gutter="20">
                <ElCol :span="8">
                    <ElFormItem label="企业名称:">
                        {{ detail.enterpriseName }}
                    </ElFormItem>
                </ElCol>

                <ElCol :span="8">
                    <ElFormItem label="统一社会信用代码:">
                        {{ detail.unifiedSocialCreditCode }}
                    </ElFormItem>
                </ElCol>
            </ElRow>

            <ElRow>
                <ElCol :span="8">
                    <ElFormItem label="企业级别:">
                        <ElTag :type=" detail?.enterpriseLevelId === '1' ? 'warning' : 'success'">
                            {{ detail.enterpriseLevel }}
                        </ElTag>
                    </ElFormItem>
                </ElCol>

                <ElCol :span="8">
                    <ElFormItem label="业务类别:">
                        {{ detail.catType }}
                    </ElFormItem>
                </ElCol>
            </ElRow>

            <ElFormItem label="企业注册地址:">
                {{ detail.registeredAddress.replace(/\,/g, '') }}
            </ElFormItem>

            <ElFormItem label="企业状态:">
                <!-- {{ detail.status }} -->
                {{ useDict('EnterpriseStatus', detail.status) }}
            </ElFormItem>

            <div class="info-title">
                企业管理员信息
            </div>

            <ElRow :gutter="20">
                <ElCol :span="8">
                    <ElFormItem label="企业管理员账号:">
                        {{ detail.enterpriseAccount }}
                    </ElFormItem>
                </ElCol>

                <ElCol :span="8">
                    <ElFormItem label="姓名:">
                        {{ detail.userName }}
                    </ElFormItem>
                </ElCol>

                <ElCol :span="8">
                    <ElFormItem label="手机号:">
                        {{ useAesDecrypt(detail.phonenumber) }}
                    </ElFormItem>
                </ElCol>
            </ElRow>
        </ElForm>

        <div style="text-align: center;margin-top: 20px;">
            <ElButton type="primary"
                      @click="onSubmit"
            >
                编辑
            </ElButton>

            <ElButton @click="goToList">
                返回列表
            </ElButton>
        </div>
    </ElCard>
</template>

<style lang="less" scoped>
.info-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 60px;
}
</style>
